package main

import (
	"fmt"
	"unicode/utf8"
)

/*
定义无参无返回值的函数
在控制台打印Hello World
*/
func sayHello() {
	fmt.Println("Hello World")
}

func sayHi(name string) {
	fmt.Printf("Hi, %s", name)
}

func add(n1 int, n2 int) int {
	return n1 + n2
}

func mergeFuncArgsType(n1, n2 int, s1, s2, s3 string, b1 bool) {
	fmt.Printf("%T, %T, %T, %T, %T, %T", n1, n2, s1, s2, s3, b1)
	fmt.Println(n1, n2, s1, s2, s3, b1)
}

func printArgs(n1, n2 int, args ...string) {
	fmt.Printf("%T, %T, %T\n", n1, n2, args)
	fmt.Println(n1, n2, args)
}

func calc(n1, n2 int) (int, int, int, int) {
	return n1 + n2, n1 - n2, n1 * n2, n1 / n2
}

func calcReturnNamecalc(n1, n2 int) (sum, difference, product, quotient int) {
	sum, difference, product, quotient = n1+n2, n1-n2, n1*n2, n1/n2
	return
}

/*
计算n的阶乘
n < 0 ：错误
n = 0 ：1
n > 0 ：n! = n * n-1!
*/
func factorial(n int) int {
	if n < 0 {
		return -1
	} else if n == 0 {
		return 1
	} else {
		return n * factorial(n-1)
	}
}

/*
汉罗塔游戏
将所有a柱上的圆盘借助b柱移动到c柱，在移动过程中保证每个柱子上的圆盘比下面圆盘小
n: a-> c(b)
n=1: a->c
n>1: n-1(a->b(c)); a-c;n-1(b->c(a))
*/

func tower(a, b, c string, layer int) {
	if layer < 0 {
		return
	}
	if layer == 1 {
		fmt.Printf("%s -> %s\n", a, c)
		return
	}
	tower(a, c, b, layer-1)
	fmt.Println("%s -> %s\n", a, c)
	tower(b, a, c, layer-1)
}

func main() {
	fmt.Println(utf8.RuneCountInString("abcdef我"))
	fmt.Println(utf8.RuneCountInString("abcdef"))
	fmt.Println(len("abcdef我"))
	fmt.Println(len("abcdef"))

	sayHello()

	sayHi("sf")

	n1, n2 := 1, 2
	fmt.Println(add(n1, n2))

	printArgs(1, 2, []string{"3", "4", "5", "6"}...)
	args := []string{"3", "4", "5", "6"}
	printArgs(1, 2, args...)
	printArgs(1, 2, args[:3]...)
}
